#include "llt_v4mapper.hh"

using namespace userFunction;

void
v4mapper::processData(lee::PktData * const pkt)
{
  tt::SixPacket * v6pkt;
  v6pkt = static_cast<tt::SixPacket *>(pkt);

  // if the map doesn't already exist, drop the packet
  if(addrMap.find(v6pkt->ipHdr.ip6_src.s6_addr32[0]) == addrMap.end()) {
    drop(pkt);
  }
  // otherwise replace the destination address and send it on
  else {
    v6pkt->ipHdr.ip6_dst = addrMap[v6pkt->ipHdr.ip6_src.s6_addr32[0]];
    normal(pkt);
  }
}

void
v4mapper::mapEntryHandler(natpt::V6NewMapEvent * ev)
{
  // sanity check
  //natpt::V6NewMapEvent * evt = dynamic_cast<natpt::V6NewMapEvent *>(ev);
  if(ev != NULL) {
    addrMap[ev->getV4()] = ev->getV6();
    std::cerr << "Got it!" << std::endl;
  }
}
